import React, { Component } from "react";
import { View, Text, TouchableOpacity, Platform } from "react-native";
import styles from "../../style/tabbar";
import { Color } from "../../style/common";
import { BGT_INFO } from "../../config/Api";
import http from "../../util/http";

const hrefs = ["Redeem", "Transfer", "Subscription"];

export default class TabBar extends Component {
  state = {
    data: {
      clear_startdate: "2018-08-20",
      clear_enddate: "2018-09-21"
    }
  };

  async getBgtInfo() {
    const data = await http.get(BGT_INFO);
    this.setState({
      data: data.data
    });
  }

  isOutDate() {
    let begin = new Date(this.state.data.clear_startdate).getTime();
    let now = new Date().getTime();
    let end = new Date(this.state.data.clear_enddate).getTime();
    if (begin <= now && now <= end) {
      console.log("enen");
      return true;
    }
    console.log("nono");
    return false;
  }

  componentWillMount() {
    this.getBgtInfo();
  }
  render() {
    const { navigate } = this.props;
    return (
      <View style={styles.tabbar}>
        {["赎回", "划转", "认购"].map((item, index) => (
          <TouchableOpacity
            key={index}
            style={styles.tabbarItem}
            onPress={() =>
              navigate(
                index != 2
                  ? hrefs[index]
                  : this.isOutDate()
                  ? "/Settlement"
                  : hrefs[index]
              )
            }
          >
            <View>
              <Text
                style={{
                  height: 35,
                  lineHeight: 35,
                  color: index == 2 ? "#fff" : "#9c9c9c",
                  textAlign: "center",
                  borderRightWidth: Platform.OS == "iOS" ? 1 : 0,
                  borderRightColor: "gray",
                  backgroundColor: index == 2 ? Color : "#f2f2f2",
                  marginLeft: 5,
                  marginRight: 5,
                  marginTop: 5,
                  marginBottom: 17,
                  borderRadius: 5,
                  overflow: "hidden"
                }}
              >
                {index != 2 ? item : this.isOutDate() ? "结算" : item}
              </Text>
            </View>
          </TouchableOpacity>
        ))}
      </View>
    );
  }
}
